package com.redoor.app.stake.basicdata.service.impl;

import com.redoor.app.stake.basicdata.dao.BasePropMapper;
import com.redoor.app.stake.basicdata.model.BaseProp;
import com.redoor.app.stake.basicdata.model.BaseStake;
import com.redoor.app.stake.basicdata.model.constants.BasePropConstants;
import com.redoor.app.stake.basicdata.model.constants.BasicDataRedisConstants;
import com.redoor.app.stake.basicdata.model.controllerModel.BasePropCriteria;
import com.redoor.app.stake.basicdata.service.BasePropRedisService;
import com.redoor.app.stake.basicdata.service.BasePropService;
import com.redoor.app.stake.common.service.RedisService;
import com.redoornetwork.framework.data.redis.util.RedisUtils;
import com.redoornetwork.framework.mybatis.service.AbstractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * Created by wangjunlei on 2018-03-10 17:05:59.
 */
@Service
public class BasePropRedisServiceImpl implements BasePropRedisService {

    @Autowired
    private RedisUtils redisUtils;

    @Override
    public boolean insertToRedis(List<BaseProp> propList) {
        if (propList==null){
            return false;
        }
        try {
            for (BaseProp prop:propList) {
                String name = prop.getName();
                if(!StringUtils.isEmpty(name)){
                    redisUtils.hset(BasicDataRedisConstants.REDIS_PROP_PRE,name.toUpperCase(), prop.getValue(),BasicDataRedisConstants.REDIS_OVER_TIME_DAY);
                }
            }
        }catch (Exception e){
            return false;
        }
        return true;
    }

    @Override
    public String getPropFromRedis(String name) {
        if(StringUtils.isEmpty(name) || !redisUtils.hHasKey(BasicDataRedisConstants.REDIS_PROP_PRE,name.toUpperCase())){
            return null;
        }
        return redisUtils.hget(BasicDataRedisConstants.REDIS_PROP_PRE,name.toUpperCase()).toString();
    }
}